import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

enum Screenroom implements Serializable {
    GoldRoom("GoldRoom",8,10),SliverRoom("SliverRoom",10,12),EmeraldRoom("EmeraldRoom",7,8),DiamondRoom("DiamondRoom",7,8),JewelRoom("JewelRoom",8,9 );
    public final int row;//行
    public final int column;//列
    private String roomName;
    private final List<Session> sessions = new ArrayList<>();
    private Screenroom(String roomName,int row, int column) {
        this.row = row;
        this.column = column;
        this.roomName = roomName;
    }
    public static Screenroom getByRoomName(String roomName) {
        for (Screenroom room : Screenroom.values()) {
            if (room.name().equals(roomName)) {
                return room;
            }
        }
        return null;
    }
    public boolean isAvailable(Film film, LocalDateTime startTime) {
        LocalDateTime newEndTime = startTime.plusMinutes(film.getDurationMinutes());
        for (Session existingSession : sessions) {
            LocalDateTime existingStart = existingSession.getStartTime();
            LocalDateTime existingEnd = existingSession.getEndTime();
            if (startTime.isBefore(existingEnd) && newEndTime.isAfter(existingStart)) {
                return false;
            }
        }
        return true;
    }
    public int getRow(){
        return this.row;
    }
    public int  getColumn(){
        return this.column;
    }
    public void addSession(Session session) {
        sessions.add(session);
    }
    public String getRoomName() {
        return this.roomName;
    }
}
